package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.bo.OccupancyBo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.HospitalizedMapper;
import com.java2207.group1.pojo.Discharge;
import com.java2207.group1.pojo.Hospitalized;
import com.java2207.group1.service.HospitalizedService;
import com.java2207.group1.vo.hospitalized.BerVo;
import com.java2207.group1.vo.hospitalized.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 15319 2022/7/27 16:46
 */
@Service("hospitalizedService")
public class HospitalizedServiceImpl implements HospitalizedService {

    @Autowired
    private HospitalizedMapper hospitalizedMapper;

    @Override
    public LayuiPageVo<Hospitalized> hospitalizedPage(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);

        List<Hospitalized> hospitalizeds = hospitalizedMapper.hospitalizedListPage(params);
        PageInfo<Hospitalized> hospitalizedPageInfo = new PageInfo<>(hospitalizeds);
        LayuiPageVo<Hospitalized> hospitalizedLayuiPageVo = new LayuiPageVo<>();
        hospitalizedLayuiPageVo.setCode(0);
        hospitalizedLayuiPageVo.setMsg("住院列表");
        hospitalizedLayuiPageVo.setCount(hospitalizedPageInfo.getTotal());
        hospitalizedLayuiPageVo.setData(hospitalizedPageInfo.getList());
        return hospitalizedLayuiPageVo;

    }

    @Override
    public int hospitalizedUpdate(Hospitalized hospitalized) {
        return hospitalizedMapper.hospitalizedUpdate(hospitalized);
    }
    @Autowired
    private DischargeServiceImpl dischargeService;

    @Override
    public int hospitalizedDelete(Hospitalized hospitalized) {
        Integer id = hospitalized.getId();
        Hospitalized hospitalized1 = hospitalizedMapper.hospitalizedById(id);
        Discharge discharge = new Discharge();
        discharge.setId(hospitalized1.getId());
        discharge.setName(hospitalized1.getName());
        discharge.setAge(hospitalized1.getAge());
        discharge.setSex(hospitalized1.getSex());
        discharge.setGuardian(hospitalized1.getGuardian());
        discharge.setDischargeDate(new Date());
        dischargeService.dischargeAdd(discharge);

        return hospitalizedMapper.hospitalizedDelete(id);
    }

    @Override
    public int hospitalizedAdd(Hospitalized hospitalized) {
        return hospitalizedMapper.hospitalizedAdd(hospitalized);
    }

    @Override
    public int hospitalizedDeleteByIds(String ids) {

        String[] id = ids.split(",");
        return hospitalizedMapper.hospitalizedDeleteByIds(id);
    }

    @Override
    public List<BerVo> setBarDate() {
        return hospitalizedMapper.setBarDate();
    }

    @Override
    public List<PieVo> setPieDate() {
        return hospitalizedMapper.setPieDate();
    }

    @Override
    public List<OccupancyBo> hospitalizedExcelPage(Map<String, Object> params) {
        return null;
    }


}
